﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Leo.Common.MQ
{
    /// <summary>
    /// MQ 消费者 基类
    /// </summary>
    public abstract class MQConsumerBase : IDisposable
    {
        protected abstract void ConnectToListen();

        private List<IMessageHandler> Handlers;
        public MQConsumerBase(List<IMessageHandler> handlers)
        {
            this.Handlers = handlers;
        }

        public void Start()
        {
            this.ConnectToListen();
        }

        protected List<IMessageHandler> GetMatchHandlers(string typeName)
        {
            return this.Handlers.FindAll((IMessageHandler x) => x.CanExecute(typeName));
        }

        protected virtual void ReleaseResources()
        {
        }

        public void Dispose()
        {
            this.ReleaseResources();
        }

    }
}
